/*
 * TableModelEvent.java  0.4.0 / Oct 24, 2010
 *
 * Copyright (c) 2010 - 2011, cute4j.com and contributors.
 *
 * This software is licensed under the LGPL version 2.1 license.
 * A copy of this license is included in the file LICENSE-LGPL.txt.
 */
package com.cute4j.swing.events;

import java.util.EventObject;

import com.cute4j.swing.table.TableModel;


/**
 * Table Model Event.
 *
 * @author Slobodan Vrkacevic
 * @version 0.4.0
 */
public class TableModelEvent extends EventObject {

// Public Static Fields. -------------------------------------------------------

  /**
   * All columns.
   */
  public static final int ALL_COLUMNS = -1;

  /**
   * Header row.
   */
  public static final int HEADER_ROW = -1;

  /**
   * Delete event type.
   */
  public static final int DELETE = -1;

  /**
   * Update event type.
   */
  public static final int UPDATE = 0;

  /**
   * Insert event type.
   */
  public static final int INSERT = 1;

// Private Static Fields. ------------------------------------------------------

  private static final long serialVersionUID = -1373413365034560012L;

// Protected Fields. -----------------------------------------------------------

  protected int type;
  protected int column;
  protected int firstRow;
  protected int lastRow;

// Public Constructors. --------------------------------------------------------

  /**
   * Constructs new TableModelEvent object.
   *
   * @param source the source
   * @param firstRow the first row
   * @param lastRow the last row
   * @param column the column.
   * @param type the type
   */
  public TableModelEvent(TableModel source, int firstRow, int lastRow,
                         int column, int type) {
    super(source);
    this.firstRow = firstRow;
    this.lastRow = lastRow;
    this.column = column;
    this.type = type;
  }

  /**
   * Constructs new TableModelEvent object.
   *
   * @param source the source
   * @param firstRow the first row
   * @param lastRow the last row
   * @param column the column.
   */
  public TableModelEvent(TableModel source, int firstRow, int lastRow,
                         int column) {
    this(source, firstRow, lastRow, column, UPDATE);
  }

  /**
   * Constructs new TableModelEvent object.
   *
   * @param source the source
   * @param firstRow the first row
   * @param lastRow the last row
   */
  public TableModelEvent(TableModel source, int firstRow, int lastRow) {
    this(source, firstRow, lastRow, ALL_COLUMNS, UPDATE);
  }

  /**
   * Constructs new TableModelEvent object.
   *
   * @param source the source
   * @param row the row
   */
  public TableModelEvent(TableModel source, int row) {
    this(source, row, row, ALL_COLUMNS, UPDATE);
  }

  /**
   * Constructs new TableModelEvent object.
   *
   * @param source the source
   */
  public TableModelEvent(TableModel source) {
    this(source, 0, Integer.MAX_VALUE, ALL_COLUMNS, UPDATE);
  }

// Public Methods. -------------------------------------------------------------

  /**
   * Returns column.
   *
   * @return column
   */
  public int getColumn() {
    return column;
  }

  /**
   * Returns first row.
   *
   * @return first row
   */
  public int getFirstRow() {
    return firstRow;
  }

  /**
   * Returns last row.
   *
   * @return last row
   */
  public int getLastRow() {
    return lastRow;
  }

  /**
   * Returns type.
   *
   * @return type.
   */
  public int getType() {
    return type;
  }

}
